package gui;
/**
 * Class responsible for drawing UI elements for the Lobby screen
 */
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.RemoteException;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JToggleButton;
import javax.swing.ScrollPaneConstants;
import javax.swing.SpinnerNumberModel;
import javax.swing.SwingConstants;
import javax.swing.border.EtchedBorder;

import model.TableSettings;
import controller.LobbyController;

public class LobbyDisplay extends Display {

	private LobbyController lobbyController;
    private JList tableList, friendList;
	private DefaultListModel listModel, friendListModel;
	private int numTables = 20, MAX_FRIENDS = 20;
	private int buttonStatus = 0;
	private int selectedTableID;
	private JToggleButton btnRefreshList;
	private JSpinner buyChipsSpinner;
	String[] tableData, friendListData;

	private JTextField txtEntry, joinBuyInTextField, createBuyInTextField;
	private String createGameName;
	private int createGameAnte, createGameMaxBet, createGameMaxPlayers;

	/**
	 * Create Lobby and link it to a lobbyController
	 * @param c Controller to be linked
	 */
	public LobbyDisplay(LobbyController c) {
		super();
		drawLobby();
		this.lobbyController = c;
	}
	
	/**
	 * Create a Lobby and link it to a lobbyController and a Display
	 * @param c controller to be linked
	 * @param lastDisplay display to be linked
	 */
	public LobbyDisplay(LobbyController c, Display lastDisplay) {
		super(lastDisplay.getFrame());
		drawLobby();
		this.lobbyController = c;
	}

	/**
	 * Draw out all the UI elements for the lobby
	 */
	private void drawLobby() {
		frame.getContentPane().removeAll();
		Dimension preferredSize = new Dimension(675,575);
		frame.setPreferredSize(preferredSize);
		frame.setMinimumSize(preferredSize);
		frame.pack();
		
		ImagePanel MAINMENU = new ImagePanel(new ImageIcon(GUI.class.getResource("/images/Menu_BG_V3.png")).getImage());
		MAINMENU.setBorder(null);
		MAINMENU.setBackground(Color.BLACK);
		frame.getContentPane().add(MAINMENU, "");
		MAINMENU.setLayout(null);
		
		final JPanel LOGOUTCONFIRM = new JPanel();
		LOGOUTCONFIRM.setBackground(Color.DARK_GRAY);
		
		LOGOUTCONFIRM.setBounds(248, 404, 142, 65);
		LOGOUTCONFIRM.setVisible(false);
		MAINMENU.add(LOGOUTCONFIRM);
		LOGOUTCONFIRM.setLayout(null);
		
		JButton btnNewButton_2 = new JButton("Yes");
		btnNewButton_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				LOGOUTCONFIRM.setVisible(false);
				lobbyController.returnToLogin();
			}
		});
		btnNewButton_2.setBounds(10, 35, 55, 28);
		LOGOUTCONFIRM.add(btnNewButton_2);
		
		JLabel lblAreYouSure = new JLabel("Log out?");
		lblAreYouSure.setFont(new Font("Segoe UI", Font.BOLD, 13));
		lblAreYouSure.setHorizontalAlignment(SwingConstants.CENTER);
		lblAreYouSure.setBounds(0, 10, 142, 16);
		lblAreYouSure.setForeground(Color.WHITE);
		LOGOUTCONFIRM.add(lblAreYouSure);
		
		JButton btnNo = new JButton("No");
		btnNo.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
		        LOGOUTCONFIRM.setVisible(false);
			}
		});
		btnNo.setBounds(77, 35, 55, 28);
		LOGOUTCONFIRM.add(btnNo);
		
		Component horizontalStrut_2 = Box.createHorizontalStrut(20);
		horizontalStrut_2.setBounds(0, 57, 20, 12);
		MAINMENU.add(horizontalStrut_2);
		
		Component horizontalStrut_3 = Box.createHorizontalStrut(20);
		horizontalStrut_3.setBounds(20, 57, 20, 12);
		MAINMENU.add(horizontalStrut_3);
		
		btnRefreshList = new JToggleButton("");
		btnRefreshList.setToolTipText("Refresh Tables");
		btnRefreshList.setForeground(Color.BLACK);
		btnRefreshList.setBackground(Color.BLACK);
		btnRefreshList.setContentAreaFilled(false);
		btnRefreshList.setIcon(new ImageIcon(GUI.class.getResource("/images/Refresh_Button.png")));
		btnRefreshList.setPressedIcon(new ImageIcon(GUI.class.getResource("/images/Refresh_Button_pressed.png")));
		btnRefreshList.setBorder(BorderFactory.createEmptyBorder());
		btnRefreshList.setBounds(50, 425, 79, 75);
		MAINMENU.add(btnRefreshList);
		
		JLabel label_5 = new JLabel("");
		label_5.setBounds(80, 7, 539, 100);
		label_5.setIcon(new ImageIcon(GUI.class.getResource("/images/mainmenu_title.jpg")));
		label_5.setVisible(false); //HIDE TITLE FOR NOW TO MAKE ROOM FOR THE BUTTONS
		MAINMENU.add(label_5);
		
		//DONT USE THIS BUTTON, USE "JOIN TABLE" BUTTON
		JButton btnJoin = new JButton("Join Game");
		btnJoin.setBounds(500, 140, 268, 28);
		btnJoin.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				//lobbyController.joinGame(1); // NEED TO SHOW LIST OF TABLES TO GET TABLEID!!!
			}
		});
		btnJoin.setVisible(false); //temporary
		
		final JScrollPane friendScrollPane = new JScrollPane();
		friendScrollPane.setBackground(new Color(255,255,255));
		friendScrollPane.setBounds(675, 0, 175, 574);
		MAINMENU.add(friendScrollPane);
		
		//friendListData = lobbyController.getFriendsList();
		friendListData = new String[]{"iamtheone188", "rcaimano", "banana", "zigosity"};
		friendListModel = new DefaultListModel();
		friendList = new JList(friendListModel);			
		
		friendScrollPane.setViewportView(friendList);
		friendScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		friendList.setForeground(Color.BLACK);
		
		for(int i=0; i<MAX_FRIENDS; i++) {
			try { friendListModel.addElement(friendListData[i]); }
			catch(Exception e) { break; }
		}
		
		JToggleButton btnFriendz = new JToggleButton("");
		btnFriendz.setSelectedIcon(new ImageIcon(GUI.class.getResource("/images/Friends_Button_pressed.png")));
		btnFriendz.setContentAreaFilled(false);
		btnFriendz.setIcon(new ImageIcon(GUI.class.getResource("/images/Friends_Button.png")));
		btnFriendz.setBounds(521, 425, 79, 75);
		btnFriendz.setToolTipText("Friends!");
		btnFriendz.setForeground(Color.BLACK);
		btnFriendz.setBackground(Color.BLACK);
		btnFriendz.setBorder(BorderFactory.createEmptyBorder());
		btnFriendz.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						if(buttonStatus == 0) {
							Dimension newSize = new Dimension(850,575);
							frame.setSize(newSize);
							buttonStatus++;
						}
						else {
							Dimension newSize = new Dimension(675,575);
							frame.setSize(newSize);
							buttonStatus--;
						}
					}
				});
		
		MAINMENU.add(btnFriendz);
		
		final JLabel lblLobbyTitle = new JLabel("Lobby");
		lblLobbyTitle.setVerticalAlignment(SwingConstants.BOTTOM);
		lblLobbyTitle.setForeground(Color.WHITE);
		lblLobbyTitle.setFont(new Font("Candara", Font.BOLD, 64));
		lblLobbyTitle.setBounds(47, 47, 257, 87);
		MAINMENU.add(lblLobbyTitle);
		
			
		JButton btnStatistics = new JButton("");
		btnStatistics.setToolTipText("Statistics");
		btnStatistics.setContentAreaFilled(false);
		btnStatistics.setForeground(Color.BLACK);
		btnStatistics.setBackground(Color.BLACK);
		btnStatistics.setIcon(new ImageIcon(GUI.class.getResource("/images/Statistics_Button.png")));
		btnStatistics.setPressedIcon(new ImageIcon(GUI.class.getResource("/images/Statistics_Button_pressed.png")));
		btnStatistics.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				lobbyController.openStatistics();
			}
		});
		btnStatistics.setBorder(BorderFactory.createEmptyBorder());
		btnStatistics.setBounds(343, 50, 79, 75);
		MAINMENU.add(btnStatistics);
		
		JButton btnSettings = new JButton("");
		btnSettings.setToolTipText("Settings");
		btnSettings.setForeground(Color.BLACK);
		btnSettings.setBackground(Color.BLACK);
		btnSettings.setContentAreaFilled(false);
		btnSettings.setIcon(new ImageIcon(GUI.class.getResource("/images/Settings_Button.png")));
		btnSettings.setPressedIcon(new ImageIcon(GUI.class.getResource("/images/Settings_Button_pressed.png")));
		btnSettings.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				lobbyController.openSettings();
			}
		});
		btnSettings.setBorder(BorderFactory.createEmptyBorder());
		btnSettings.setBounds(434, 50, 79, 75);
		MAINMENU.add(btnSettings);
		
		JToggleButton btnLogout = new JToggleButton("");
		btnLogout.setSelectedIcon(new ImageIcon(GUI.class.getResource("/images/Exit_Button_pressed.png")));
		btnLogout.setToolTipText("Logout");
		btnLogout.setForeground(Color.BLACK);
		btnLogout.setBackground(Color.BLACK);
		btnLogout.setContentAreaFilled(false);
		btnLogout.setIcon(new ImageIcon(GUI.class.getResource("/images/Exit_Button.png")));
		btnLogout.setBounds(525, 50, 79, 75);
		btnLogout.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				LOGOUTCONFIRM.setVisible(false);
				lobbyController.returnToLogin();
			}
		});
		btnLogout.setBorder(BorderFactory.createEmptyBorder());
		MAINMENU.add(btnLogout);
		
		final JPanel joinBuyInPanel = new JPanel();
		joinBuyInPanel.setBackground(Color.DARK_GRAY);
		joinBuyInPanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
		joinBuyInPanel.setBounds(160, 245, 332, 58);
		joinBuyInPanel.setVisible(false);
		MAINMENU.add(joinBuyInPanel);
		
		JLabel lblJoinHowManyChips = new JLabel("How many chips would you like to bring to this table?");
		lblJoinHowManyChips.setForeground(Color.WHITE);
		joinBuyInPanel.add(lblJoinHowManyChips);
		
		joinBuyInTextField = new JTextField();
		joinBuyInPanel.add(joinBuyInTextField);
		joinBuyInTextField.setColumns(10);
		
		JButton joinBuyInConfirm = new JButton("Confirm");
		joinBuyInConfirm.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {				
				try {
					String temp = joinBuyInTextField.getText();
					boolean formattingError = false;
					
					for (int i = 0; i < temp.length(); i++) {
						if (!('0' <= temp.charAt(i) && temp.charAt(i) <= '9')) {
							formattingError = true;
						}
					}
					
					if (formattingError) {
						JOptionPane.showMessageDialog(frame, "Please enter a valid number of chips");
						formattingError = false;
					}
					else{
						joinBuyInPanel.setVisible(false);
						int chips = Integer.parseInt(temp);
						lobbyController.joinGame(selectedTableID+1, chips);
					}
				} catch (RemoteException e1) {
					e1.printStackTrace();
				}
				
			}
		});
		joinBuyInConfirm.setBounds(50, 50, 90, 28);
		joinBuyInPanel.add(joinBuyInConfirm);
		
		final JPanel createBuyInPanel = new JPanel();
		createBuyInPanel.setBackground(Color.DARK_GRAY);
		createBuyInPanel.setBounds(160, 245, 332, 58);	
		createBuyInPanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
		createBuyInPanel.setVisible(false);
		MAINMENU.add(createBuyInPanel);
		
		JLabel lblCreateHowManyChips = new JLabel("How many chips would you like to bring to this table?");
		lblCreateHowManyChips.setForeground(Color.WHITE);
		createBuyInPanel.add(lblCreateHowManyChips);
		
		createBuyInTextField = new JTextField();
		createBuyInPanel.add(createBuyInTextField);
		createBuyInTextField.setColumns(10);
		
		JButton createBuyInConfirm = new JButton("Confirm");
		createBuyInConfirm.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
								
				try {
					String temp = createBuyInTextField.getText();
					boolean formattingError = false;
					
					for (int i = 0; i < temp.length(); i++) {
						if (!('0' <= temp.charAt(i) && temp.charAt(i) <= '9')) {
							formattingError = true;
						}
					}
					
					if (formattingError) {
						JOptionPane.showMessageDialog(frame, "Please enter a valid number of chips");
						formattingError = false;
					}
					else{
						createBuyInPanel.setVisible(false);
						int chips = Integer.parseInt(temp);
						lobbyController.createGame(new TableSettings(createGameName, createGameMaxPlayers, createGameAnte, createGameMaxBet), chips);
					}
				} catch (RemoteException e1) {
					e1.printStackTrace();
				}		
				
			}
		});
		createBuyInConfirm.setBounds(50, 50, 90, 28);
		createBuyInPanel.add(createBuyInConfirm);
		
		final JPanel buyChipsPanel = new JPanel();
		buyChipsPanel.setBackground(Color.DARK_GRAY);
		buyChipsPanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
		buyChipsPanel.setBounds(160, 245, 332, 58);		
		buyChipsPanel.setVisible(false);
		MAINMENU.add(buyChipsPanel);
		
		JLabel lblHowManyChips = new JLabel("How many chips would you like to purchase?");
		lblHowManyChips.setForeground(Color.WHITE);		
		buyChipsPanel.add(lblHowManyChips);
		
		buyChipsSpinner = new JSpinner();
		buyChipsSpinner.setModel(new SpinnerNumberModel(500, 500, 10000, 500));
		buyChipsSpinner.setBounds(30, 30, 50, 28);
		buyChipsPanel.add(buyChipsSpinner);	
		
		
		final JPanel gameOptionsPanel = new JPanel();		
		gameOptionsPanel.setBackground(Color.DARK_GRAY);
		gameOptionsPanel.setBounds(212, 160, 276, 241);
		gameOptionsPanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
		gameOptionsPanel.setVisible(false);
		MAINMENU.add(gameOptionsPanel);
		gameOptionsPanel.setLayout(null);
		
		JLabel lblGameName = new JLabel("Table name:");
		lblGameName.setBounds(10, 59, 90, 16);
		lblGameName.setForeground(Color.WHITE);
		gameOptionsPanel.add(lblGameName);
		
		JLabel lblMaxPlayers = new JLabel("Max players:");
		lblMaxPlayers.setForeground(Color.WHITE);
		lblMaxPlayers.setBounds(10, 91, 90, 16);
		gameOptionsPanel.add(lblMaxPlayers);
		
		JLabel lblAnte = new JLabel("Ante:");
		lblAnte.setForeground(Color.WHITE);
		lblAnte.setBounds(10, 123, 90, 16);
		gameOptionsPanel.add(lblAnte);
		
		JLabel lblMaxBet = new JLabel("Max bet:");
		lblMaxBet.setForeground(Color.WHITE);
		lblMaxBet.setBounds(10, 155, 90, 16);
		gameOptionsPanel.add(lblMaxBet);
		
		JLabel lblGameSettings = new JLabel("GAME SETTINGS");
		lblGameSettings.setFont(new Font("Candara", Font.BOLD, 24));
		lblGameSettings.setForeground(Color.WHITE);
		lblGameSettings.setHorizontalAlignment(SwingConstants.CENTER);
		lblGameSettings.setBounds(0, 6, 276, 39);
		gameOptionsPanel.add(lblGameSettings);
		
		final JTextField gameNameField = new JTextField();
		gameNameField.setBounds(118, 57, 145, 20);
		gameOptionsPanel.add(gameNameField);
		gameNameField.setColumns(10);
		
		final JSpinner anteSpinner = new JSpinner();
		anteSpinner.setModel(new SpinnerNumberModel(5, 5, 100, 5));
		anteSpinner.setBounds(118, 121, 49, 20);
		gameOptionsPanel.add(anteSpinner);
		
		final JSpinner maxPlayersSpinner = new JSpinner();
		maxPlayersSpinner.setModel(new SpinnerNumberModel(6, 2, 6, 1));
		maxPlayersSpinner.setBounds(118, 89, 49, 20);
		gameOptionsPanel.add(maxPlayersSpinner);
		
		final JSpinner maxBetSpinner = new JSpinner();
		maxBetSpinner.setModel(new SpinnerNumberModel(500, 50, 5000, 50));
		maxBetSpinner.setBounds(118, 153, 49, 20);
		gameOptionsPanel.add(maxBetSpinner);
		
		final JScrollPane lobbyScrollPane = new JScrollPane();
		lobbyScrollPane.setBackground(new Color(255,255,255));
		lobbyScrollPane.setBounds(50, 145, 552, 230);
		MAINMENU.add(lobbyScrollPane);
		
		final JButton btnCreateTable = new JButton("Create Table");
		final JButton btnJoinTable = new JButton("Join Table");
		
		final JLabel lblPlzSelectTable = new JLabel("Please select a table.");
		lblPlzSelectTable.setForeground(Color.RED);
		lblPlzSelectTable.setHorizontalAlignment(SwingConstants.CENTER);
		lblPlzSelectTable.setBounds(262, 496, 148, 16);
		lblPlzSelectTable.setVisible(false);
		MAINMENU.add(lblPlzSelectTable);
		
		JButton btnCreateGame_1 = new JButton("Create Game");
		btnCreateGame_1.setBounds(25, 200, 110, 28);
		btnCreateGame_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(gameNameField.getText().equals("")){
					JOptionPane.showMessageDialog(frame, "Please enter a valid table name.");
				}
				else{
					createGameName = gameNameField.getText();
					SpinnerNumberModel m1 = (SpinnerNumberModel)maxPlayersSpinner.getModel();
					createGameMaxPlayers = m1.getNumber().intValue();
					SpinnerNumberModel m2 = (SpinnerNumberModel)maxBetSpinner.getModel();
					createGameMaxBet = m2.getNumber().intValue();
					SpinnerNumberModel m3 = (SpinnerNumberModel)anteSpinner.getModel();
					createGameAnte = m3.getNumber().intValue();					
					
					createBuyInPanel.setVisible(true);
					lblLobbyTitle.setVisible(false);
					lobbyScrollPane.setVisible(false);
					gameOptionsPanel.setVisible(false);
					btnCreateTable.setVisible(false);
					btnRefreshList.setVisible(false);
					btnJoinTable.setVisible(false);
					lblPlzSelectTable.setVisible(false);
					
				}
			}
		});
		gameOptionsPanel.add(btnCreateGame_1);	
		
		JButton btnBuyChips = new JButton("");
		btnBuyChips.setToolTipText("Buy Chips");
		btnBuyChips.setContentAreaFilled(false);
		btnBuyChips.setForeground(Color.BLACK);
		btnBuyChips.setBackground(Color.BLACK);
		btnBuyChips.setIcon(new ImageIcon(GUI.class.getResource("/images/DollarSign_Button.png")));
		btnBuyChips.setPressedIcon(new ImageIcon(GUI.class.getResource("/images/DollarSign_Button_pressed.png")));
		btnBuyChips.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				buyChipsPanel.setVisible(true);
				lblLobbyTitle.setVisible(false);
				lobbyScrollPane.setVisible(false);
				gameOptionsPanel.setVisible(false);
				btnCreateTable.setVisible(false);
				btnRefreshList.setVisible(false);
				btnJoinTable.setVisible(false);
				lblPlzSelectTable.setVisible(false);
			}
		});
		btnBuyChips.setBorder(BorderFactory.createEmptyBorder());
		btnBuyChips.setBounds(252, 50, 79, 75);
		MAINMENU.add(btnBuyChips);
		
		JButton buyChipsConfirm = new JButton("Confirm");
		buyChipsConfirm.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {	
				SpinnerNumberModel m1 = (SpinnerNumberModel)buyChipsSpinner.getModel();
				int chips = m1.getNumber().intValue();
				boolean deposited = lobbyController.addCredit(chips);
				
				if(!deposited){
					JOptionPane.showMessageDialog(frame, "Your balance is over 500.\nWe will not give you more chips!", "Nice Try", JOptionPane.ERROR_MESSAGE);
				}
				buyChipsPanel.setVisible(false);
				lblLobbyTitle.setVisible(true);
				lobbyScrollPane.setVisible(true);
				gameOptionsPanel.setVisible(false);
				btnCreateTable.setVisible(true);
				btnRefreshList.setVisible(true);
				btnJoinTable.setVisible(true);
				lblPlzSelectTable.setVisible(false);
			}
		});
		buyChipsConfirm.setBounds(50, 50, 90, 28);
		buyChipsPanel.add(buyChipsConfirm);
			
					
		tableData = new String[numTables];
		listModel = new DefaultListModel();
		tableList = new JList(listModel);
		
		lobbyScrollPane.setViewportView(tableList);
		lobbyScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		tableList.setForeground(Color.BLACK);	
		
		
		btnRefreshList.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
					lblPlzSelectTable.setVisible(false);
					
					try {
						tableData = lobbyController.refreshTables();
					} catch (RemoteException e) { e.printStackTrace(); }					
					
					listModel.clear();
					for(int i=0; i<numTables; i++) {
						try {listModel.addElement(tableData[i]);}
						catch (ArrayIndexOutOfBoundsException e) { break; }
					}
			}
		});
		
		
		
		
		JButton btnCancel_3 = new JButton("Cancel");
		btnCancel_3.setBounds(146, 200, 110, 28);
		btnCancel_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				lblLobbyTitle.setVisible(true);
				lobbyScrollPane.setVisible(true);
				gameOptionsPanel.setVisible(false);
				btnCreateTable.setVisible(true);
				btnRefreshList.setVisible(true);
				btnJoinTable.setVisible(true);
				lblPlzSelectTable.setVisible(false);
			}
		});
		gameOptionsPanel.add(btnCancel_3);
		
		
		btnJoinTable.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				selectedTableID = tableList.getSelectedIndex();
				if(selectedTableID < 0) {
					lblPlzSelectTable.setVisible(true);
				}
				else {
					joinBuyInPanel.setVisible(true);
					lblLobbyTitle.setVisible(false);
					lobbyScrollPane.setVisible(false);
					gameOptionsPanel.setVisible(false);
					btnCreateTable.setVisible(false);
					btnRefreshList.setVisible(false);
					btnJoinTable.setVisible(false);
					lblPlzSelectTable.setVisible(false);					
				}
			}
		});
		btnJoinTable.setBounds(280, 429, 111, 28);
		MAINMENU.add(btnJoinTable);
		
		btnCreateTable.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				lblLobbyTitle.setVisible(false);
				lobbyScrollPane.setVisible(false);
				gameOptionsPanel.setVisible(true);
				btnCreateTable.setVisible(false);
				btnRefreshList.setVisible(false);
				btnJoinTable.setVisible(false);
				lblPlzSelectTable.setVisible(false);
			}
		});
		btnCreateTable.setBounds(280, 466, 111, 28);
		btnCreateTable.setVisible(true);
		MAINMENU.add(btnCreateTable);

		
		frame.setVisible(true);
	}
	
	/**
	 * Controls the button that refreshes the lobby pane
	 */
	public void refresh(){
		btnRefreshList.doClick();
	}
}
